<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<style type="text/css">
	*{
		text-align: center;
	}
	span{
		color:red;
	}
</style>
	<link rel="stylesheet" type="text/css" href="css/zzsc.css">
	<link rel="stylesheet" type="text/css" href="starability-minified/starability-all.min.css"/>
</head>
<body>
<h2>添加题目</h2><hr/>

<form id="f1" method="post">

	后台路径: <input type="text" name="url"><p/>

	<p style="width:412px;text-align: left;margin: auto;"><textarea style="text-align: left;" rows="20" cols="90" name="content" id="ta"></textarea></p>
	方法名: <input type="text" name="method"><p/>
	<fieldset  style="margin:auto;width:260px;" class="starability-basic">
		难度等级:<input type="radio" id="rate5-1" name="degree" value="5" />
					<label for="rate5-1" title="Amazing">5 stars</label>

					<input type="radio" id="rate4-1" name="degree" value="4" />
					<label for="rate4-1" title="Very good">4 stars</label>

					<input type="radio" id="rate3-1" name="degree" value="3" checked/>
					<label for="rate3-1" title="Average">3 stars</label>

					<input type="radio" id="rate2-1" name="degree" value="2" />
					<label for="rate2-1" title="Not good">2 stars</label>

					<input type="radio" id="rate1-1" name="degree" value="1" />
					<label for="rate1-1" title="Terrible">1 star</label>
				</fieldset>
			<input type="button" value="添加"  onclick="tijiao()"/><p/>

</form>
</body>

<script src="${pageContext.request.contextPath}/js/jquery-1.12.4.min.js"></script>
<script>
	function tijiao() {
		$.ajax({
			type: "POST",//方法类型
			dataType: "json",//预期服务器返回的数据类型
			url: "${pageContext.request.contextPath }/dati/add",
			data: $('#f1').serialize(),
			success: function (result) {
				if (result.code == 1) {
					alert("添加成功!");
					location.replace("${pageContext.request.contextPath}/dati/list?pagenum=1")
				}else if(result.code == 101){
					location.replace("${pageContext.request.contextPath}/login.jsp?error="+encodeURI('登录过期,请重新登录'))
				}else{
					alert("添加失败,未知错误!");
				}
			},
			error:function () {
				alert("添加失败!");
			}
		});
	}
</script>


</html>